#ifndef _BUTTON_H
#define _BUTTON_H
#include "stdint.h"


#define FLEX_BTN_SCAN_FREQ_HZ 50 // How often flex_button_scan () is called
#define FLEX_MS_TO_SCAN_CNT(ms) (ms / (1000 / FLEX_BTN_SCAN_FREQ_HZ))

typedef void (*button_response_callback)(void*);

typedef enum {
    BTN_EVENT_PRESS_DOWN = 0,
    BTN_EVENT_PRESS_CLICK,
    BTN_EVENT_PRESS_NONE,

}button_event_t;

typedef struct {

    uint8_t(*usr_button_read)(void*);
    button_response_callback cb;
    uint8_t _status;
    uint8_t _event;
    uint16_t _scan_cnt;
    uint16_t click_hold_start_tick;
} button_t;

#ifdef __cplusplus
extern "C" {
#endif

    int32_t button_register(button_t* btn);
    button_event_t button_event_read(button_t* btn);
    uint8_t button_scan(void);


#ifdef __cplusplus
}
#endif

#endif